package com.donghuayuan.kotlincar

import android.Manifest
import android.content.Intent
import android.os.Build
import android.os.Bundle
import android.view.View
import androidx.appcompat.app.AppCompatActivity
import com.donghuayuan.kotlincar.databinding.ActivityMainBinding
import com.donghuayuan.kotlincar.utils.UtilsContent
import com.yanzhenjie.permission.AndPermission
import com.yanzhenjie.permission.runtime.Permission


class MainActivity : AppCompatActivity(), View.OnClickListener {
    private lateinit var binding: ActivityMainBinding
    var permissionsArr = arrayOf(
        Permission.WRITE_EXTERNAL_STORAGE,
        Permission.READ_EXTERNAL_STORAGE,
        Permission.WRITE_CONTACTS,
        Manifest.permission.BLUETOOTH,
        Manifest.permission.BLUETOOTH_ADMIN,
        Manifest.permission.BLUETOOTH,
        Permission.ACCESS_COARSE_LOCATION
    )

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        this.binding = ActivityMainBinding.inflate(layoutInflater)
        setContentView(this.binding.root)
        println("启动了mainActivity")
        //获取权限
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            permissionCheck()
        }

        binding.mainBtn1.setOnClickListener(this@MainActivity)
        binding.mainBtn2.setOnClickListener(this@MainActivity)


    }

    private fun permissionCheck() {
        AndPermission.with(this)
            .runtime()
            .permission(permissionsArr)
            .onGranted { permission ->
                {
                    //同意权限集合List
                    UtilsContent.initMMKV(this@MainActivity)
                }
                UtilsContent.initMMKV(this@MainActivity)
            }
            .onDenied { permission ->
                //同意权限集合List
            }
            .start()
    }

    override fun onClick(p0: View?) {
        when (p0) {
            binding.mainBtn1 -> {

            }
            //汽车品牌大全
            binding.mainBtn2 -> {
//                this@MainActivity.startActivity(Intent().apply {
//                    intent.setClass(this@MainActivity,LogoActivity::class.java)
//                })
//                startActivity(Intent(intent.setClass(this@MainActivity,LogoActivity::class.java)))
                Intent().apply {
                    intent.setClass(this@MainActivity, LogoActivity::class.java)
                    startActivity(intent)
                }
            }
            else -> {
                Intent().apply {
                    intent.setClass(this@MainActivity, LiveDateAndModeActivity::class.java)
                    startActivity(intent)
                }
            }
        }
    }

}